package misc;

import java.util.HashMap;

public class EnvFactory {

	private HashMap<String, Env> m_EnvPool;
	
	public EnvFactory() {
		m_EnvPool = new HashMap<String, Env>();
	}
	
	public Env getInstance(String envClassName) {
		
		Class envClass;
		Env envInstance;
		
		envInstance = null;
		
		if (m_EnvPool.containsKey(envClassName)) {
			envInstance = m_EnvPool.get(envClassName);
		}
		
		try {
			envClass = Class.forName(envClassName);
			envInstance = (Env) envClass.newInstance();
			m_EnvPool.put(envClassName, envInstance);
			
		} catch (InstantiationException e) {
			e.printStackTrace();
			
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
		return envInstance;
	}
	

}
